package com.chehejia.devmng.platform.base.model.page;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author SongJian
 * Created by SongJian at 2018/3/28.
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel("分页返回值")
public class PageResult<E> implements Serializable {

    private static final long serialVersionUID = -6387086497638925166L;

    /**
     * 当前页数据结果集
     */
    @ApiModelProperty("分页数据集合")
    private List<E> results = new ArrayList<E>();

    /**
     * 当前页码
     */
    @ApiModelProperty("当前页码")
    private Integer pageNo = 0;

    /**
     * 每页大小
     */
    @ApiModelProperty("每页大小")
    private Integer pageSize = 0;

    /**
     * 总页数
     */
    @ApiModelProperty("总页数")
    private Long pageCount = 0L;

    /**
     * 总记录数
     */
    @ApiModelProperty("总记录数")
    private Long totalCount = 0L;

    public <T> PageResult<T> convert(List<T> results) {
        return PageResult.<T>builder()
                .pageNo(getPageNo())
                .pageSize(getPageSize())
                .pageCount(getPageCount())
                .totalCount(getTotalCount())
                .results(results)
                .build();
    }
}
